home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3260 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  50 lines

  1. Path: news.pge.com!usenet
  2. From: psk3@pge.com (Phillip Knight)
  3. Newsgroups: comp.lang.c++
  4. Subject: overiding c++ stream classes anyone?
  5. Date: 23 Jan 1996 01:20:47 GMT
  6. Organization: Pacific Gas and Electric
  7. Message-ID: <4e1d5f$5en@news02.comp.pge.com>
  8. References: <4cqbja$62n@earth.njcc.com>
  9. NNTP-Posting-Host: psk3ws04.comp.pge.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.6
  13.  
  14. I have pulled the last hair out of my head and still have not solved this 
  15. problem:
  16.  
  17.     class X : public ostream {
  18.     public:
  19.     ...
  20.     X& operator<<(X& (*f)(X&)) { return (*f)(*this); }
  21.     };
  22.  
  23.  
  24.     X& newl(X& os) {
  25.         cerr << "this never gets printed" << endl;
  26.     }
  27.  
  28.     main() {
  29.        X foo;
  30.        foo << "test one";
  31.        foo << endl;
  32.  
  33.        foo << "test two" << endl;
  34.     }
  35.  
  36. so the problem is simple: how do i get my manipulator newl to be called?  This 
  37. program as stands does not compile, because inclusion of the operator '<<' 
  38. (used in order to execute the manipulator) causes class X to no longer 
  39. recognize the base class operators (it only recognizes X's operator <<).  
  40. taking the operator out of the class and into the code as a function doesn't 
  41. solve the problem either as newl never gets called.
  42.  
  43. so anyone know a simple way of overloading a manipulator?  (all this when all
  44. i really need is a virtual flush...)
  45.  
  46. thanks in advance...
  47. phil knight
  48. psk3@pge.com
  49.  
  50.